package com.wenbo.wenbo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wenbo.wenbo.entity.Tenant;
import com.wenbo.wenbo.mapper.TenantMapper;
import com.wenbo.wenbo.service.ITenantService;
import com.wenbo.wenbo.service.MsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 租客信息表 服务实现类
 * </p>
 *
 * @author ywb
 * @since 2022-07-04
 */
@Service
@Slf4j
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements ITenantService {


    @Value("${tencent.tenant}")
    private Integer tenant;
    @Resource
    private MsgService msgService;

    @Override
    public void tenant() {
        LocalDate now = LocalDate.now();
                int month = now.getMonthValue();
                int year = now.getYear();
                List<Tenant> list = list();
                list.forEach(x->{
                    LocalDate time = x.getTime();
                    int dayOfMonth= time.getDayOfMonth();
                    LocalDate  should = LocalDate.of(year, month, dayOfMonth).plusDays(-1);
                    if(should.compareTo(now)==0){
                        System.err.println(x.getName()+should.toString()+"今天交房租了");
                        String[] params = new String[6];
                        params[0] = x.getName();
                        params[1] = "杨文博";
                        params[2] = time.toString();
                        params[3] = String.valueOf(x.getMoney());
                        params[4] = String.valueOf(x.getWater());
                        params[5] = String.valueOf(x.getMoney()+x.getWater());
                        msgService.sendMsg("鹏鹏记录日志", x.getPhone(), params,tenant);
                log.info(x.getName()+"-"+time+"-"+params[5]);
            }
        });
    }


}
